package com.qiya.LiaoDa.ZViewPagerAdapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


import com.qiya.LiaoDa.R;

import java.util.List;

public class LinearAdapter extends RecyclerView.Adapter<LinearAdapter.LinearViewHoder> {

    private Context mcontext;
    private List<String> mlist ;

    public LinearAdapter(Context context, List<String> list){
        this.mcontext=context;
        this.mlist=list;
    }

    @NonNull
    @Override
    public LinearAdapter.LinearViewHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //TODO 1在这里创建view
        return new LinearViewHoder(LayoutInflater.from(mcontext).inflate(R.layout.item_linear_adapter,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull LinearAdapter.LinearViewHoder holder, final int position) {
        //TODO 3 通过holder设置内容
        holder.textView.setText("西红柿炒鸡蛋");
        holder.textView.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("WrongConstant")
            @Override
            public void onClick(View view) {
                Toast.makeText(mcontext,"你选择了"+position,1).show();
            }
        });
    }

    @Override
    public int getItemCount() {
        //这里设置列表长度
        //return mlist.size();
        return 30;
    }

    class LinearViewHoder extends RecyclerView.ViewHolder{

        //TODO 2 在viewHoder里面创建其他控件
        private TextView textView;

        //TODO 1 这里的view就是每一个item长什么样子，所以去创建
        public LinearViewHoder(@NonNull View itemView) {
            super(itemView);
            //控件在那个view里面就用那个view获取组件
            textView =itemView.findViewById(R.id.tv_titel);
        }
    }
}
